package com.zaofan.utils;

import java.util.TimerTask;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.zaofan.cache.FrontCache;

/**
 * 网站数据更新 任务 5分钟
 * 
 * @author Administrator
 *
 */
public class TaskDataContextListner implements ServletContextListener {
	private static java.util.Timer timer = null;
	private FrontCache cache;

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		if (timer != null) {
			timer.cancel();
		}
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		cache = new FrontCache();
		timer = new java.util.Timer(true);
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				System.err.println("执行----------------------数据更新------------------任务");
				try {
					cache.loadAllCache();
				} catch (Exception e) {
					e.printStackTrace();
				}
				System.err.println("任务----------------------数据更新------------------结束");
			}
		}, 0, 5 * 60 * 1000);
	}

}
